//
//  RHNewProductListViewController.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/7/13.
//

#import "RHNewProductListViewController.h"
#import "RHNewProductCell.h"
#import "RHProductDetailViewController.h"
#import "RHProductIntroduceVC.h"

@interface RHNewProductListViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView       *tableView;

@property (nonatomic, strong) NSArray *dataArr;
@end

@implementation RHNewProductListViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"新品".rh_localized;
    self.view.backgroundColor = CFTabViewBgColor;
    [self setupUI];
}

- (void)setupUI{
    self.dataArr = @[@"home_circle01",@"home_circle02",@"home_circle03"];
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setSeparatorColor:UIColor.clearColor];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView registerClass:[RHNewProductCell class] forCellReuseIdentifier:@"NewProductCell"];
    [self.view addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
    
  
    [self.tableView addHeaderRefresh:^{
      
    }];

    
}

#pragma mark - UITableViewDelegate,UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  
    RHNewProductCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewProductCell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  
    cell.prductImgView.image = [UIImage imageNamed:self.dataArr[indexPath.section]];
    cell.prductNameLab.text = [NSString stringWithFormat:@"Product %02zd",indexPath.section+1];
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc]init];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    RHProductIntroduceVC *vc = [[RHProductIntroduceVC alloc] init];
    
    [self.navigationController pushViewController:vc animated:YES];
    
}



@end
